# 判断是否登录
def check_session(request):
    key = request.COOKIES.get('usernameKey')
    if request.session.get(key, 1) == 1:  # 如果没有用户session，参数就为1
        return False
    else:
        return True


# 返回dict
def dictfetchall(cursor):
    "Return all rows from a cursor as a dict"
    columns = [col[0] for col in cursor.description]
    return [
        dict(zip(columns, row))
        for row in cursor.fetchall()
    ]
